/**
 * $Id: TerminalChangeCodec.java,v 1.2 2010-09-15 11:57:07 gaudenz Exp $
 * Copyright (c) 2006, Gaudenz Alder
 */
package com.kg.rails.component.editor.io;

import com.kg.rails.component.editor.model.GraphModel.mxTerminalChange;
import org.w3c.dom.Node;

import java.util.Map;

/**
 * Codec for mxChildChanges. This class is created and registered
 * dynamically at load time and used implicitely via Codec
 * and the CodecRegistry.
 */
public class TerminalChangeCodec extends ObjectCodec {

    /**
     * Constructs a new model codec.
     */
    public TerminalChangeCodec() {
        this(new mxTerminalChange(), new String[]{"model", "previous"},
                new String[]{"cell", "terminal"}, null);
    }

    /**
     * Constructs a new model codec for the given arguments.
     */
    public TerminalChangeCodec(Object template, String[] exclude,
                               String[] idrefs, Map<String, String> mapping) {
        super(template, exclude, idrefs, mapping);
    }

    /* (non-Javadoc)
      * @see com.kg.rails.component.editor.io.ObjectCodec#afterDecode(com.kg.rails.component.editor.io.Codec, org.w3c.dom.Node, java.lang.Object)
      */
    @Override
    public Object afterDecode(Codec dec, Node node, Object obj) {
        if (obj instanceof mxTerminalChange) {
            mxTerminalChange change = (mxTerminalChange) obj;

            change.setPrevious(change.getTerminal());
        }

        return obj;
    }

}
